package com.scu.servlet;

import com.scu.dao.LikeDao;
import com.scu.entity.LikeCount;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "LikeServlet", value = "/LikeServlet")
public class LikeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String post_id = request.getParameter("post_id");

        int idint = Integer.parseInt(post_id);//前端需要传递一个id

        LikeCount likeCount = new LikeCount();
        likeCount.setPost_id(idint);

        try {
            boolean like = LikeDao.whethereLike(likeCount);
            if(like){
                int likes = LikeDao.like(likeCount);
            }else{
                int dislike = LikeDao.deleteLike(likeCount);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        System.out.println("123");
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

}
